import { Tray, Menu } from "electron"

import logo from './proxy.png?asset'

const initTray = (mainWindow: any) => {
  const tray = new Tray(logo);

  tray.setToolTip('proxy_G_serve');

  tray.on('click', () => {
    if(mainWindow.isVisible()){
      mainWindow.hide()
    }else{
      mainWindow.show()
    }
  })

  tray.on('right-click', () => {
    const menuConfig = Menu.buildFromTemplate([
      {
        label: '退出',
        click: ()=> {
          mainWindow.destroy()
        }
      }
    ])

    tray.popUpContextMenu(menuConfig)
  })
}

export default initTray